package com.zr.planClass.controller;


import com.zr.planClass.model.modelmin.*;
import com.zr.planClass.service.PlanClassMinService;
import com.zr.util.ErrorMessageClass;
import com.zr.util.ResultBuilderVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 非常狂躁的猪 on 2019/12/24.
 */
@RestController
@CrossOrigin
public class PlanClassMinController {

    @Autowired
    private PlanClassMinService planClassMinService;

    @PostMapping("subClass/add") //添加
    public ResultVo addPlanClass(@RequestBody @Valid PlanClassAddVo planClassAddVo, BindingResult bindingResult){

        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        ResultVo resultVo = planClassMinService.add(planClassAddVo);

        return resultVo;
    }




    @PostMapping("subClass/update") //修改
    public ResultVo updatePlan(@RequestBody @Valid PlanClassUpdateVo planClassUpdateVo, BindingResult bindingResult){

        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }

        ResultVo resultVo = planClassMinService.update(planClassUpdateVo);

        return  resultVo;
    }

    @PostMapping("subClass/queryPage") //分页
    public ResultVo queryAllPlan(@RequestBody PlanClassSelectVo planClassSelectVo){

        ResultVo resultVo = planClassMinService.queryAllPlan(planClassSelectVo);

        return  resultVo;
    }

    @PostMapping("subClass/updateStatus") //修改状态
    public ResultVo updateStatus(@RequestBody @Valid PlanClassUpdateStatus planClassUpdateStatus, BindingResult bindingResult){

        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }

        ResultVo resultVo = planClassMinService.updateStatusById(planClassUpdateStatus);
        return  resultVo;
    }






}
